#include <stdio.h>
#include "Thread_Pool.h"
#include "Thread_Pool_Init.h"
#include "Thread_Pool_Manager.h"
#include "Thread_Pool_Task.h"
#include "Thread_Pool_Worker.h"
#include "stdlib.h"
#include "unistd.h"

void *myTask(void *arg)
{
	printf("Now the task is running!\n");
	printf("The tid = %ld\n", pthread_self());

	return NULL;
}

int main()
{
	int i = 0;

	printf("hello test!\n");	
	printf("下面是线程池的测试:\n");

	//1. 初始化一个线程池
	Thread_Poolp mypoolp = NULL;
	//Thread_Poolp ThreadPool_Init(u16 max_task, u16 max_thread, u16 min_thread)
	mypoolp = ThreadPool_Init(20, 20, 2);	
	if(mypoolp == NULL)
	{
		perror("mypoolp init failed!");
		exit(-1);
	}	
	printf("pool create succeed!\n");

	//2. 在线程池中添加任务
	for(i=0; i<5; i++)
	{
		ThreadPool_InsertTask(mypoolp, myTask, NULL);
		puts("put task into pool OK!!!");
	}

	sleep(10);
	//x. 销毁线程池
	//if(i==5 && mypoolp->task_num == 0)//当所有任务完成后，结束线程池
	ThreadPool_Destroy(mypoolp);
	

	return 0;
}
